<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

function status($status){
    if($status == 1){
        $str = "<span class='label label-success radius'>正常</span>";
    }elseif($status==0){
        $str = "<span class='label label-danger radius'>待审</span>";
    }else {
        $str = "<span class='label label-danger radius'>删除</span>";
    }

    return $str;
}

/**
 * @param $url
 * @param int $type 0 get 1 post
 * @param array $data
 * @return mixed
 */
function doCurl($url, $type = 0, $data = []){
    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_HEADER,0);

    if($type == 1){
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
    }

    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

function show($status = 1, $msg = '', $data = [])
{
    return [
        'status' => $status,
        'msg' => $msg,
        'data' => $data,
    ];
}

//商户入驻申请文案
function bisRegister($status)
{
    switch ($status){
        case 0:
            $str = "待审核，审核后平台方会发送邮件通知，请关注邮件";
            break;
        case 1:
            $str = "入驻申请成功";
            break;
        case 2:
            $str = "非常抱歉，您提交的资料不符合条件，请重新提交";
            break;
        default:
            $str = "该审核已被删除";
    }
    return $str;
}

//分页
function pagination($obj)
{
    if(!$obj){
        return '';
    }
    return '<div class="cl pd-5 bg-1 bk-gray mt-20 tp5-o2o">'.$obj->render().'</div>';
}

function getSeCityName($path)
{
    if(empty($path)) {
        return '';
    }
        if(preg_match('/,/',$path)){
            $cityPath = explode(',',$path);
            $cityId = $cityPath[1];
        }else {
            $cityId = $path;
        }

        $city = model('City')->get($cityId);
        return $city->name;
}

//子分类
function se_category($path)
{
    if(empty($path)){
        return '';
    }
    if(preg_match('/,/',$path)){
        $category_path = explode(',',$path);
    }
    unset($category_path[0]);
    if(preg_match('/|/',$category_path[1])){
        $category_path = explode('|',$category_path[1]);
    }
    $category = model('category')->all($category_path);
    if($category){
        $category = (new \think\Collection($category))->toArray();
    }
    $str = '';
    foreach($category as $item){
        $str .= '<input type="checkbox" checked="checked"  name="se_category_id[]" id="checkbox-moban" value="'. $item['id'] .'"  />'.$item['name'];
        $str .= '<label for="checkbox-moban">&nbsp;</label>';
    }
    return $str;
}
